/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Library General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor Boston, MA 02110-1301,  USA
 */

#define _GNU_SOURCE
#include "gui.h"
#include <unistd.h>
#include <Ecore_X.h>
#include <time.h>

int l_co=0;

void close_popup(void *data, Evas_Object *obj, void *event_info)
{
	if(pop_win) evas_object_del (pop_win);
}

void popup_message(char *message, char *msg, int butt_state)
{
	Evas_Object *bg, *inwin, *vbox, *lb;
	
	pop_win = elm_win_add(NULL, "inwin", ELM_WIN_DIALOG_BASIC);
	elm_win_title_set(pop_win, "Message");
	elm_win_autodel_set(pop_win, 1);

	bg = elm_bg_add(pop_win);
	elm_win_resize_object_add(pop_win, bg);
	evas_object_size_hint_weight_set(bg, 1.0, 1.0);
	evas_object_show(bg);

	inwin = elm_win_inwin_add(pop_win);
	elm_object_style_set(inwin, "minimal_vertical");
	evas_object_show(inwin);

	vbox = elm_box_add(pop_win);
	elm_win_inwin_content_set(inwin, vbox);
	evas_object_show(vbox);
	
	popup_lb = elm_label_add(pop_win);
	elm_label_label_set(popup_lb, message);
	elm_box_pack_end(vbox, popup_lb);
	evas_object_show(popup_lb);

	lb = elm_label_add(pop_win);
	elm_label_label_set(lb, msg);
	elm_box_pack_end(vbox, lb);
	evas_object_show(lb);
	
	//add close button
	popup_bt = elm_button_add(pop_win);
	elm_button_label_set(popup_bt, "Done");
	evas_object_size_hint_weight_set(popup_bt, 1.0, 1.0);
	evas_object_size_hint_align_set(popup_bt, 0.5, -1.0);
	elm_box_pack_end(vbox, popup_bt);
	if (butt_state) evas_object_show(popup_bt);
	evas_object_smart_callback_add(popup_bt, "clicked", close_popup, NULL);
	
	evas_object_resize(pop_win, 320, 240);
	evas_object_show(pop_win);
}

void popup_warning(char *message, char *msg, void (*yes_func)(void), void (*no_func)(void))
{
	Evas_Object *bg, *inwin, *vbox, *lb, *hbox;
	
	warn_win = elm_win_add(NULL, "inwin", ELM_WIN_DIALOG_BASIC);
	elm_win_title_set(warn_win, "Message");
	elm_win_autodel_set(warn_win, 1);

	bg = elm_bg_add(warn_win);
	elm_win_resize_object_add(warn_win, bg);
	evas_object_size_hint_weight_set(bg, 1.0, 1.0);
	evas_object_show(bg);

	inwin = elm_win_inwin_add(warn_win);
	elm_object_style_set(inwin, "minimal_vertical");
	evas_object_show(inwin);

	vbox = elm_box_add(warn_win);
	elm_win_inwin_content_set(inwin, vbox);
	evas_object_show(vbox);
	
	popup_lb = elm_label_add(warn_win);
	elm_label_label_set(popup_lb, message);
	elm_box_pack_end(vbox, popup_lb);
	evas_object_show(popup_lb);

	lb = elm_label_add(warn_win);
	elm_label_label_set(lb, msg);
	elm_box_pack_end(vbox, lb);
	evas_object_show(lb);

	//add a hbox
	hbox = elm_box_add(warn_win);
	elm_box_horizontal_set(hbox, 1);
	elm_box_homogenous_set(hbox, 1);
	evas_object_size_hint_weight_set(hbox, 1.0, 0.0);
	evas_object_size_hint_align_set(hbox, -1.0, 0.0);
	elm_box_pack_end(vbox, hbox);
	evas_object_show(hbox);
	
	//add yes button
	popup_bt = elm_button_add(warn_win);
	elm_button_label_set(popup_bt, "Yes");
	evas_object_size_hint_weight_set(popup_bt, 1.0, 1.0);
	evas_object_size_hint_align_set(popup_bt, -1.0, -1.0);
	elm_box_pack_end(hbox, popup_bt);
	evas_object_smart_callback_add(popup_bt, "clicked", (void *)yes_func, NULL);
	evas_object_show(popup_bt);
	
	//add no button
	popup_bt = elm_button_add(warn_win);
	elm_button_label_set(popup_bt, "Cancel");
	evas_object_size_hint_weight_set(popup_bt, 1.0, 1.0);
	evas_object_size_hint_align_set(popup_bt, -1.0, -1.0);
	elm_box_pack_end(hbox, popup_bt);
	evas_object_smart_callback_add(popup_bt, "clicked", (void *)no_func, NULL);
	evas_object_show(popup_bt);
	
	evas_object_resize(warn_win, 320, 240);
	evas_object_show(warn_win);
}

char *dir_gl_label_get(const void *data, Evas_Object *obj, const char *part)
{
	_dir *dir_gl = (_dir *)data;
	char tystr[255], *ty;
	char *label = dir_gl->path;
	
	ty = strrchr(label, '/');
	ty ++;
	sprintf(tystr, "%s", ty);
	ty = strdup(tystr);
	return (ty);
}

Evas_Object *dir_gl_icon_get(const void *data, Evas_Object *obj, const char *part)
{
	_dir *dir_gl = (_dir *)data;
	char buf[PATH_MAX], buf1[PATH_MAX];
	
	if (!strcmp(part, "elm.swallow.icon"))
	{
		Evas_Object *ic = elm_icon_add(obj);
		Evas_Object *ic1 = elm_icon_add(obj);
		
		snprintf(buf, sizeof(buf), "%s/folder.png", launcher_dir);
		snprintf(buf1, sizeof(buf1), "%s/generic.png", launcher_dir);
		elm_icon_file_set(ic, buf, NULL);
		elm_icon_file_set(ic1, buf1, NULL);
		evas_object_size_hint_aspect_set(ic, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
		evas_object_size_hint_aspect_set(ic1, EVAS_ASPECT_CONTROL_VERTICAL, 1, 1);
		if (dir_gl->type == DT_DIR) return ic;
		else return ic1;
	}
	return NULL;
}

Eina_Bool dir_gl_state_get(const void *data, Evas_Object *obj, const char *part)
{
   return 0;
}

void dir_gl_del(const void *data, Evas_Object *obj)
{
}

void create_dir_browser_page(void *data, Evas_Object *obj, void *event_info)
{
	dir_browser_page_win = elm_win_add(NULL, "sel_direc", ELM_WIN_BASIC);
	elm_win_title_set(dir_browser_page_win, "Select Wallpaper");

	Evas_Object *bg, *vbox, *hbox, *hbox1, *up_button, *home_button, *enter_dir_button;
	Evas_Object *add_dir_button, *cancel_button, *dir_list;
	static Winlist wl;
	
	//add background
	bg = elm_bg_add(dir_browser_page_win);
	elm_win_resize_object_add(dir_browser_page_win, bg);
	evas_object_size_hint_weight_set(bg, 1.0, 1.0);
	evas_object_show(bg);

	//add vbox 3
	vbox = elm_box_add(dir_browser_page_win);
	elm_win_resize_object_add(dir_browser_page_win, vbox);
	evas_object_size_hint_weight_set(vbox, 1.0, 1.0);
	evas_object_show(vbox);

	// add button hbox
	hbox = elm_box_add(dir_browser_page_win);
	elm_box_horizontal_set(hbox, 1);
	evas_object_size_hint_weight_set(hbox, 1.0, 0.0);
	evas_object_size_hint_align_set(hbox, -1.0, 0.0);
	elm_box_pack_end(vbox, hbox);
	evas_object_show(hbox);

	//add up button to hbox
	up_button = elm_button_add(dir_browser_page_win);
	elm_button_label_set(up_button, "Up");
	evas_object_size_hint_weight_set(up_button, 1.0, 1.0);
	evas_object_size_hint_align_set(up_button, -1.0, -1.0);
	elm_box_pack_end(hbox, up_button);
	evas_object_show(up_button);

	//add home button to hbox
	home_button = elm_button_add(dir_browser_page_win);
	elm_button_label_set(home_button, "Home");
	evas_object_size_hint_weight_set(home_button, 1.0, 1.0);
	evas_object_size_hint_align_set(home_button, -1.0, -1.0);
	elm_box_pack_end(hbox, home_button);
	evas_object_show(home_button);

	//add enter dir button to hbox
	enter_dir_button = elm_button_add(dir_browser_page_win);
	elm_button_label_set(enter_dir_button, "Enter Dir");
	evas_object_size_hint_weight_set(enter_dir_button, 1.0, 1.0);
	evas_object_size_hint_align_set(enter_dir_button, -1.0, -1.0);
	elm_box_pack_end(hbox, enter_dir_button);
	evas_object_show(enter_dir_button);

	//add list to vbox now
	dir_list = elm_genlist_add(dir_browser_page_win);
	//elm_genlist_bounce_set(dir_list, 0, 0);
	evas_object_size_hint_weight_set(dir_list, 1.0, 1.0);
	evas_object_size_hint_align_set(dir_list, -1.0, -1.0);
	elm_genlist_multi_select_set(dir_list, 0);
	elm_box_pack_end(vbox, dir_list);
	evas_object_show(dir_list);
	evas_object_smart_callback_add(dir_list, "clicked", dir_list_select, dir_list);
	evas_object_smart_callback_add(up_button, "clicked", up_button_clicked, dir_list);
	evas_object_smart_callback_add(home_button, "clicked", home_button_clicked, dir_list);   
	evas_object_smart_callback_add(enter_dir_button, "clicked", dir_list_select, dir_list); 

	//genlist class defs
	itc_dir_list.item_style     		= "default";
	itc_dir_list.func.label_get 		= dir_gl_label_get;
	itc_dir_list.func.icon_get  		= dir_gl_icon_get;
	itc_dir_list.func.state_get 	= dir_gl_state_get;
	itc_dir_list.func.del       		= dir_gl_del;
	
	// add button hbox1
	hbox1 = elm_box_add(dir_browser_page_win);
	elm_box_horizontal_set(hbox1, 1);
	evas_object_size_hint_weight_set(hbox1, 1.0, 0.0);
	evas_object_size_hint_align_set(hbox1, -1.0, 0.0);
	elm_box_pack_end(vbox, hbox1);
	evas_object_show(hbox1);

	//add add_dir button to hbox1
	add_dir_button = elm_button_add(dir_browser_page_win);
	elm_button_label_set(add_dir_button, "Set Wallpaper");
	evas_object_size_hint_weight_set(add_dir_button, 1.0, 1.0);
	evas_object_size_hint_align_set(add_dir_button, -1.0, -1.0);
	elm_box_pack_end(hbox1, add_dir_button);
	evas_object_show(add_dir_button);
	evas_object_smart_callback_add(add_dir_button, "clicked", add_dir_button_clicked, dir_list);

	//add cancel button to hbox1
	cancel_button = elm_button_add(dir_browser_page_win);
	elm_button_label_set(cancel_button, "Done");
	evas_object_size_hint_weight_set(cancel_button, 1.0, 1.0);
	evas_object_size_hint_align_set(cancel_button, -1.0, -1.0);
	elm_box_pack_end(hbox1, cancel_button);
	evas_object_show(cancel_button);
	wl.win = dir_browser_page_win;
	wl.li = dir_list;
	evas_object_smart_callback_add(cancel_button, "clicked", cancel_button_clicked, &wl);
	
	//set delete callback for this window
	evas_object_smart_callback_add(dir_browser_page_win, "delete-request", cancel_button_clicked, &wl);

	//load directory data
	load_dir(dir_list, "/");

	evas_object_resize(dir_browser_page_win, 480, 600);
	evas_object_show(dir_browser_page_win);
}

char *gl_label_get(const void *data, Evas_Object *obj, const char *part)
{
	_Cat *cat = (_Cat *)data;
	char tystr[255], *ty;
	
	sprintf(tystr, "%s", cat->app);
	ty = strdup(tystr);
	return (ty);
}

Evas_Object *gl_icon_get(const void *data, Evas_Object *obj, const char *part)
{
	_Cat *cat = (_Cat *)data;

	if (!strcmp(part, "elm.swallow.end"))
	{
		Evas_Object *bx, *pr_lb;
		char txt[255];

		//show check box
		bx = elm_box_add(obj);
		elm_box_horizontal_set(bx, 1);

		//add a label for category
		sprintf(txt, "%s", cat->cat);
		pr_lb = elm_label_add(obj);
		elm_label_label_set(pr_lb, txt);
		elm_box_pack_end(bx, pr_lb);
		evas_object_show(pr_lb);   
		evas_object_show(bx);
		
		return bx;
	}
	return NULL;
}

Eina_Bool gl_state_get(const void *data, Evas_Object *obj, const char *part)
{
   return 0;
}

void gl_del(const void *data, Evas_Object *obj)
{
}

static void
my_hover_bt_1(void *data, Evas_Object *obj, void *event_info)
{
   Evas_Object *hv = data;
   
   evas_object_show(hv);
}

void app_button_clicked(void *data, Evas_Object *obj, void *event_info)
{
	Evas_Object *app_cat_win;
	app_cat_win = elm_win_add(NULL, "Set Categories", ELM_WIN_BASIC);
	elm_win_title_set(app_cat_win, "Set Categories");

	Evas_Object *bg, *vbox, *hbox;
	Evas_Object *cancel_button, *bt, *bx;
	static Winlist wl;
	
	//add background
	bg = elm_bg_add(app_cat_win);
	elm_win_resize_object_add(app_cat_win, bg);
	evas_object_size_hint_weight_set(bg, 1.0, 1.0);
	evas_object_show(bg);

	//add vbox
	vbox = elm_box_add(app_cat_win);
	elm_win_resize_object_add(app_cat_win, vbox);
	evas_object_size_hint_weight_set(vbox, 1.0, 1.0);
	evas_object_show(vbox);

	//add a hbox
	hbox = elm_box_add(app_cat_win);
	elm_box_horizontal_set(hbox, 1);
	evas_object_size_hint_weight_set(hbox, 1.0, 0.0);
	evas_object_size_hint_align_set(hbox, -1.0, 0.0);
	elm_box_pack_end(vbox, hbox);
	evas_object_show(hbox);
	
	//add the app label
	app_lb = elm_label_add(app_cat_win);
	elm_label_label_set(app_lb, "");
	elm_box_pack_end(hbox, app_lb);
	evas_object_show(app_lb);
	
	//add the category hover
	hv = elm_hover_add(app_cat_win);
	cat_bt = elm_button_add(app_cat_win);
	elm_button_label_set(cat_bt,"Category");
	evas_object_smart_callback_add(cat_bt, "clicked", my_hover_bt_1, hv);
	evas_object_size_hint_weight_set(hv, 0.0, 0.0);
	evas_object_size_hint_align_set(hv, 0.5, 0.0);
	elm_box_pack_end(hbox, cat_bt);
	evas_object_show(cat_bt);
	elm_hover_parent_set(hv, app_cat_win);
	elm_hover_target_set(hv, cat_bt);

	bt = elm_button_add(app_cat_win);
	elm_button_label_set(bt, "Category");
	elm_hover_content_set(hv, "middle", bt);
	evas_object_show(bt);

	bx = elm_box_add(app_cat_win);
	//add categories
	add_hs_items (app_cat_win, bx, bt, 0);
	evas_object_show(bx);
	elm_hover_content_set(hv, "bottom", bx); 
	
	//add a list
	list = elm_genlist_add(app_cat_win);
	//elm_genlist_bounce_set(list, 0, 0);
	evas_object_size_hint_weight_set(list, 1.0, 1.0);
	evas_object_size_hint_align_set(list, -1.0, -1.0);
	elm_list_multi_select_set(list, 0);
	elm_box_pack_end(vbox, list);
	evas_object_show(list);
	evas_object_smart_callback_add(list, "selected", app_select, list);

	//genlist class defs
	itc_list.item_style     	= "default";
	itc_list.func.label_get 	= gl_label_get;
	itc_list.func.icon_get  	= gl_icon_get;
	itc_list.func.state_get 	= gl_state_get;
	itc_list.func.del       	= gl_del;

	//add cancel button
	cancel_button = elm_button_add(app_cat_win);
	elm_button_label_set(cancel_button, "Done");
	evas_object_size_hint_weight_set(cancel_button, 1.0, 0.0);
	evas_object_size_hint_align_set(cancel_button, -1.0, -1.0);
	elm_box_pack_end(vbox, cancel_button);
	evas_object_show(cancel_button);
	wl.win = app_cat_win;
	wl.li = list;
	evas_object_smart_callback_add(cancel_button, "clicked", cancel_button_clicked, &wl);

	//set delete callback for this window
	evas_object_smart_callback_add(app_cat_win, "delete-request", cancel_button_clicked, &wl);
	populate_app_list(list);
	evas_object_show(app_cat_win);
}

void set_button_clicked(void *user_data, Evas_Object *obj, const char *em, const char *src)
{
	//show the settings page
	//if(set_win != NULL) return;
	set_win = elm_win_add(NULL, "Preferences", ELM_WIN_BASIC);
	elm_win_title_set(set_win, "Preferences");

	Evas_Object *bg, *vbox, *cancel_button;
	static Winlist wl;
    
	char pixmaps[255], shr[255], launcher_dir[255];
	strcpy(launcher_dir, "/usr/share/launcher");
	strcpy(pixmaps, "/usr/share/pixmaps");
	strcpy(shr, "/usr/share/icons/shr/86x86/apps");
	
	//add background
	bg = elm_bg_add(set_win);
	elm_win_resize_object_add(set_win, bg);
	evas_object_size_hint_weight_set(bg, 1.0, 1.0);
	evas_object_show(bg);

    //add a vbox
    vbox = elm_box_add(set_win);
	elm_win_resize_object_add(set_win, vbox);
	evas_object_size_hint_weight_set(vbox, 1.0, 1.0);
	evas_object_show(vbox);
	
	//add a toolbar
  	pref_tb = elm_toolbar_add(set_win);
	elm_scroller_bounce_set(pref_tb, 0, 0);
    evas_object_size_hint_weight_set(pref_tb, 1.0, 0.0);
    evas_object_size_hint_align_set(pref_tb, -1.0, 1.0);
    elm_box_pack_end(vbox, pref_tb);
	evas_object_show(pref_tb);

    //add another vbox to hold widgets
    pref_vbox = elm_box_add(set_win);
	evas_object_size_hint_weight_set(pref_vbox, 1.0, 1.0);
    elm_box_pack_end(vbox, pref_vbox);
	evas_object_show(pref_vbox);
	
	//ic = elm_icon_add(set_win);
	//snprintf(buf, sizeof(buf), "/usr/share/launcher/%s.png", icon);
	//elm_icon_file_set(ic, buf, NULL);
	strcpy(pref_grp[0], "Quick");
	tb_item = elm_toolbar_item_add(pref_tb, NULL/*ic*/, pref_grp[0], show_prefs, &pref_grp[0]);
	strcpy(pref_grp[1], "Apps");
	elm_toolbar_item_add(pref_tb, NULL/*ic*/, pref_grp[1], show_prefs, &pref_grp[1]);
	strcpy(pref_grp[2], "Date");
	elm_toolbar_item_add(pref_tb, NULL/*ic*/, pref_grp[2], show_prefs, &pref_grp[2]);
	strcpy(pref_grp[3], "General");
	elm_toolbar_item_add(pref_tb, NULL/*ic*/, pref_grp[3], show_prefs, &pref_grp[3]);
	
/*	//add set cat seq application button
	bt = elm_button_add(set_win);
	elm_button_label_set(bt, "Categories");
	evas_object_size_hint_weight_set(bt, 1.0, 1.0);
	evas_object_size_hint_align_set(bt, -1.0, 0.0);
	elm_box_pack_end(box, bt);
	evas_object_show(bt);
	evas_object_smart_callback_add(bt, "clicked", set_seq, (char *) "Category");

	//add set call application button
	set_call = elm_button_add(set_win);
	elm_button_label_set(set_call, "Set Call App");
	evas_object_size_hint_weight_set(set_call, 0.0, 1.0);
	evas_object_size_hint_align_set(set_call, -1.0, -1.0);
	elm_box_pack_end(hbox, set_call);
	evas_object_show(set_call);
	
	//add an entry
	en_calls = elm_entry_add(set_win);
	elm_entry_entry_set(en_calls, app_calls);
	evas_object_size_hint_weight_set(en_calls, 1.0, 1.0);
	evas_object_size_hint_align_set(en_calls, -1.0, -1.0);
	elm_box_pack_end(hbox, en_calls);
	evas_object_show(en_calls);
	evas_object_smart_callback_add(set_call, "clicked", set_call_clicked, en_calls);

	//add set sms application button
	set_sms = elm_button_add(set_win);
	elm_button_label_set(set_sms, "Set SMS App");
	evas_object_size_hint_weight_set(set_sms, 0.0, 1.0);
	evas_object_size_hint_align_set(set_sms, -1.0, -1.0);
	elm_box_pack_end(hbox, set_sms);
	evas_object_show(set_sms);
	
	//add an entry
	en_sms = elm_entry_add(set_win);
	elm_entry_entry_set(en_sms, app_sms);
	evas_object_size_hint_weight_set(en_sms, 1.0, 1.0);
	evas_object_size_hint_align_set(en_sms, -1.0, -1.0);
	elm_box_pack_end(hbox, en_sms);
	evas_object_show(en_sms);
	evas_object_smart_callback_add(set_sms, "clicked", set_sms_clicked, en_sms);*/

	//add cancel button
	cancel_button = elm_button_add(set_win);
	elm_button_label_set(cancel_button, "Done");
	evas_object_size_hint_weight_set(cancel_button, 1.0, 0.0);
	evas_object_size_hint_align_set(cancel_button, -1.0, 0.0);
	elm_box_pack_end(vbox, cancel_button);
	evas_object_show(cancel_button);
	wl.win = set_win;
	wl.li = NULL;
	evas_object_smart_callback_add(cancel_button, "clicked", cancel_button_clicked, &wl);
	
	//set delete callback for this window
	evas_object_smart_callback_add(set_win, "delete-request", cancel_button_clicked, &wl);

	elm_toolbar_item_select(tb_item);
	evas_object_resize(set_win, 480, 600);	
	evas_object_show(set_win);
}

void create_cat_dialog(void *data, Evas_Object *obj, void *event_info)
{
	Evas_Object *bg, *inwin, *lb, *bt, *bt1, *entry, *vbox, *hbox, *hbox1;

	cat_dialog = elm_win_add(NULL, "inwin", ELM_WIN_DIALOG_BASIC);
	elm_win_title_set(cat_dialog, "Add Category");
	elm_win_autodel_set(cat_dialog, 1);

	bg = elm_bg_add(cat_dialog);
	elm_win_resize_object_add(cat_dialog, bg);
	evas_object_size_hint_weight_set(bg, 1.0, 1.0);
	evas_object_show(bg);

	inwin = elm_win_inwin_add(cat_dialog);
	elm_object_style_set(inwin, "minimal_vertical");

	//add vbox 
	vbox = elm_box_add(cat_dialog);
	elm_win_resize_object_add(cat_dialog, vbox);
	evas_object_size_hint_weight_set(vbox, 1.0, 1.0);
	elm_win_inwin_content_set(inwin, vbox);
	evas_object_show(vbox);

	//add hbox to vbox
	hbox = elm_box_add(cat_dialog);
	elm_box_horizontal_set(hbox, 1);
	evas_object_size_hint_weight_set(hbox, 1.0, 0.0);
	evas_object_size_hint_align_set(hbox, -1.0, 0.0);
	elm_box_pack_end(vbox, hbox);
	evas_object_show(hbox);

	//add a label to hbox
	lb = elm_label_add(cat_dialog);
	elm_label_label_set(lb,"Category:");
	elm_box_pack_end(hbox, lb);
	evas_object_show(lb);

	//add an entry to hbox
	entry = elm_entry_add(cat_dialog);
	elm_entry_entry_set(entry, "New Cat");
	elm_entry_single_line_set(entry, 1);
	elm_entry_editable_set(entry, 1);
	elm_entry_line_wrap_set(entry, 0);
	elm_box_pack_end(hbox, entry);
	evas_object_show(entry);

	//add another hbox
	hbox1 = elm_box_add(cat_dialog);
	elm_box_horizontal_set(hbox1, 1);
	elm_box_homogenous_set(hbox1, 1);
	elm_box_pack_end(vbox, hbox1);
	evas_object_show(hbox1);
	
	//add yes button
	bt = elm_button_add(cat_dialog);
	elm_button_label_set(bt, "Add");
	evas_object_size_hint_align_set(bt, -1.0, -1.0);
	elm_box_pack_end(hbox1, bt);
	evas_object_show(bt);
	evas_object_smart_callback_add(bt, "clicked", cat_dialog_add, entry);
	
	//add close button
	bt1 = elm_button_add(cat_dialog);
	elm_button_label_set(bt1, "Cancel");
	elm_box_pack_end(hbox1, bt1);
	evas_object_show(bt1);
	evas_object_smart_callback_add(bt1, "clicked", cat_win_del, cat_dialog);

	evas_object_show(inwin);
	
	evas_object_resize(cat_dialog, 480, 640);
	evas_object_show(cat_dialog);
}

void ren_cat_dialog(void *data, Evas_Object *obj, void *event_info)
{
	Evas_Object *bg, *inwin, *lb, *bt, *bt1, *entry, *vbox, *hbox, *hbox1;

	cat_dialog = elm_win_add(NULL, "inwin", ELM_WIN_DIALOG_BASIC);
	elm_win_title_set(cat_dialog, "Rename Category");
	elm_win_autodel_set(cat_dialog, 1);

	bg = elm_bg_add(cat_dialog);
	elm_win_resize_object_add(cat_dialog, bg);
	evas_object_size_hint_weight_set(bg, 1.0, 1.0);
	evas_object_show(bg);

	inwin = elm_win_inwin_add(cat_dialog);
	elm_object_style_set(inwin, "minimal_vertical");

	//add vbox 
	vbox = elm_box_add(cat_dialog);
	elm_win_resize_object_add(cat_dialog, vbox);
	evas_object_size_hint_weight_set(vbox, 1.0, 1.0);
	elm_win_inwin_content_set(inwin, vbox);
	evas_object_show(vbox);

	//add hbox to vbox
	hbox = elm_box_add(cat_dialog);
	elm_box_horizontal_set(hbox, 1);
	evas_object_size_hint_weight_set(hbox, 1.0, 0.0);
	evas_object_size_hint_align_set(hbox, -1.0, 0.0);
	elm_box_pack_end(vbox, hbox);
	evas_object_show(hbox);

	//add a label to hbox
	lb = elm_label_add(cat_dialog);
	elm_label_label_set(lb,"New Name:");
	elm_box_pack_end(hbox, lb);
	evas_object_show(lb);

	//add an entry to hbox
	entry = elm_entry_add(cat_dialog);
	elm_entry_entry_set(entry, "New     ");
	elm_entry_single_line_set(entry, 1);
	elm_entry_editable_set(entry, 1);
	elm_entry_line_wrap_set(entry, 0);
	elm_entry_select_all(entry);
	elm_box_pack_end(hbox, entry);
	evas_object_show(entry);

	//add another hbox
	hbox1 = elm_box_add(cat_dialog);
	elm_box_horizontal_set(hbox1, 1);
	elm_box_homogenous_set(hbox1, 1);
	elm_box_pack_end(vbox, hbox1);
	evas_object_show(hbox1);
	
	//add yes button
	bt = elm_button_add(cat_dialog);
	elm_button_label_set(bt, "Rename");
	evas_object_size_hint_align_set(bt, -1.0, -1.0);
	elm_box_pack_end(hbox1, bt);
	evas_object_show(bt);
	evas_object_smart_callback_add(bt, "clicked", cat_dialog_ren, entry);
	
	//add close button
	bt1 = elm_button_add(cat_dialog);
	elm_button_label_set(bt1, "Cancel");
	elm_box_pack_end(hbox1, bt1);
	evas_object_show(bt1);
	evas_object_smart_callback_add(bt1, "clicked", cat_win_del, cat_dialog);

	evas_object_show(inwin);
	
	evas_object_resize(cat_dialog, 480, 640);
	evas_object_show(cat_dialog);
}

char *cat_label_get(const void *data, Evas_Object *obj, const char *part)
{
	char *_cat = (char *)data;
	char *ty = strdup(_cat);
	return (ty);
}

Evas_Object *cat_icon_get(const void *data, Evas_Object *obj, const char *part)
{
	return NULL;
}

Eina_Bool cat_state_get(const void *data, Evas_Object *obj, const char *part)
{
   return 0;
}

void cat_del (const void *data, Evas_Object *obj)
{
}

void cat_launcher(void)
{
	Evas_Object *bg, *cat_lau, *vbox, *vbox1, *butt;

	cat_lau = elm_win_add(NULL, "cat_lau", ELM_WIN_BASIC);
	elm_win_title_set(cat_lau, "Manage Categories");
	evas_object_smart_callback_add(cat_lau, "delete-request", cat_win_del, cat_lau);
	
	//add background
	bg = elm_bg_add(cat_lau);
	elm_win_resize_object_add(cat_lau, bg);
	evas_object_size_hint_weight_set(bg, 1.0, 1.0);
	evas_object_show(bg);

	//add vbox 
	vbox = elm_box_add(cat_lau);
	elm_win_resize_object_add(cat_lau, vbox);
	evas_object_size_hint_weight_set(vbox, 1.0, 1.0);
	evas_object_show(vbox);

	//add vbox1 
	vbox1 = elm_box_add(cat_lau);
	evas_object_size_hint_align_set(vbox1, -1.0, 0.0);
	elm_box_pack_end(vbox, vbox1);
	evas_object_show(vbox1);
	
	//add button to set app categories
	butt = elm_button_add(cat_lau);
	elm_button_label_set(butt, "Set App Categories");
	evas_object_size_hint_weight_set(butt, 1.0, 0.0);
	evas_object_size_hint_align_set(butt, -1.0, 0.0);
	elm_box_pack_end(vbox1, butt);
	evas_object_show(butt);
	evas_object_smart_callback_add(butt, "clicked", app_button_clicked, NULL);

	//add button to manage categories
	butt = elm_button_add(cat_lau);
	elm_button_label_set(butt, "Cutomize Categories");
	evas_object_size_hint_weight_set(butt, 1.0, 0.0);
	evas_object_size_hint_align_set(butt, -1.0, 0.0);
	elm_box_pack_end(vbox1, butt);
	evas_object_show(butt);
	evas_object_smart_callback_add(butt, "clicked", edit_cat, NULL);

	//set category sequence
	butt = elm_button_add(cat_lau);
	elm_button_label_set(butt, "Category Sequence");
	evas_object_size_hint_weight_set(butt, 1.0, 0.0);
	evas_object_size_hint_align_set(butt, -1.0, 0.0);
	elm_box_pack_end(vbox1, butt);
	evas_object_show(butt);
	evas_object_smart_callback_add(butt, "clicked", (void *)set_seq_page, (char *)"Category");
	
	//add cancel button
	butt = elm_button_add(cat_lau);
	elm_button_label_set(butt, "Cancel");
	evas_object_size_hint_weight_set(butt, 1.0, 0.0);
	evas_object_size_hint_align_set(butt, -1.0, 1.0);
	elm_box_pack_end(vbox, butt);
	evas_object_show(butt);
	evas_object_smart_callback_add(butt, "clicked", cat_win_del, cat_lau);

	evas_object_show(cat_lau);
	elm_toolbar_item_select(tb_item);
}

void edit_cat(void *data, Evas_Object *obj, void *event_info)
{
	Evas_Object *bg, *cat_win, *vbox, *hbox, *add_cat_button, *del_cat_button, *done_button, *fr, *lb, *hbox1, *ren_cat_button;

	cat_win = elm_win_add(NULL, "cat", ELM_WIN_BASIC);
	elm_win_title_set(cat_win, "Edit Categories");
	evas_object_smart_callback_add(cat_win, "delete-request", cat_win_del, cat_win);
	
	//add background
	bg = elm_bg_add(cat_win);
	elm_win_resize_object_add(cat_win, bg);
	evas_object_size_hint_weight_set(bg, 1.0, 1.0);
	evas_object_show(bg);

	//add vbox 
	vbox = elm_box_add(cat_win);
	elm_win_resize_object_add(cat_win, vbox);
	evas_object_size_hint_weight_set(vbox, 1.0, 1.0);
	evas_object_show(vbox);

	//add a hbox
	hbox1 = elm_box_add(cat_win);
	elm_box_horizontal_set(hbox1, 1);
	evas_object_size_hint_weight_set(hbox1, 1.0, 0.0);
	evas_object_size_hint_align_set(hbox1, -1.0, 0.0);
	elm_box_pack_end(vbox, hbox1);
	evas_object_show(hbox1);
	
	// add a frame
	fr = elm_frame_add(cat_win);
	elm_object_style_set(fr, "outdent_top");
	evas_object_size_hint_weight_set(fr, 0.0, 0.0);
	evas_object_size_hint_align_set(fr, 0.0, -1.0);
	elm_box_pack_end(hbox1, fr);
	evas_object_show(fr);

	// add a label
	lb = elm_label_add(cat_win);
	elm_label_label_set(lb, "Application Categories");
	elm_frame_content_set(fr, lb);
	evas_object_show(lb);  
	
	//add list to vbox now
	cat_list = elm_genlist_add(cat_win);
	//elm_genlist_bounce_set(cat_list, 0, 0);
	evas_object_size_hint_weight_set(cat_list, 1.0, 1.0);
	evas_object_size_hint_align_set(cat_list, -1.0, -1.0);
	elm_list_multi_select_set(cat_list, 0);
	elm_box_pack_end(vbox, cat_list);
	evas_object_show(cat_list);
	//evas_object_smart_callback_add(cat_list, "clicked", cat_list_selected, cat_list);

	//genlist class defs
	itc2.item_style     		= "default";
	itc2.func.label_get 	= cat_label_get;
	itc2.func.icon_get  	= cat_icon_get;
	itc2.func.state_get 	= cat_state_get;
	itc2.func.del      		= cat_del;
	
	//add hbox to vbox
	hbox = elm_box_add(cat_win);
	elm_box_horizontal_set(hbox, 1);
	evas_object_size_hint_weight_set(hbox, 1.0, 0.0);
	evas_object_size_hint_align_set(hbox, -1.0, 0.0);
	elm_box_pack_end(vbox, hbox);
	evas_object_show(hbox);
	
	//add button to add categories
	add_cat_button = elm_button_add(cat_win);
	elm_button_label_set(add_cat_button, "Add");
	evas_object_size_hint_weight_set(add_cat_button, 1.0, 1.0);
	evas_object_size_hint_align_set(add_cat_button, -1.0, -1.0);
	elm_box_pack_end(hbox, add_cat_button);
	evas_object_show(add_cat_button);
	evas_object_smart_callback_add(add_cat_button, "clicked", create_cat_dialog, cat_list);

	//add button to add categories
	ren_cat_button = elm_button_add(cat_win);
	elm_button_label_set(ren_cat_button, "Rename");
	evas_object_size_hint_weight_set(ren_cat_button, 1.0, 1.0);
	evas_object_size_hint_align_set(ren_cat_button, -1.0, -1.0);
	elm_box_pack_end(hbox, ren_cat_button);
	evas_object_show(ren_cat_button);
	evas_object_smart_callback_add(ren_cat_button, "clicked", ren_cat_dialog, cat_list);
	
	//add button to del categories
	del_cat_button = elm_button_add(cat_win);
	elm_button_label_set(del_cat_button, "Delete");
	evas_object_size_hint_weight_set(del_cat_button, 1.0, 1.0);
	evas_object_size_hint_align_set(del_cat_button, -1.0, -1.0);
	elm_box_pack_end(hbox, del_cat_button);
	evas_object_show(del_cat_button);
	evas_object_smart_callback_add(del_cat_button, "clicked", del_cat_button_clicked, cat_list);

	//add done button
	done_button = elm_button_add(cat_win);
	elm_button_label_set(done_button, "Done");
	evas_object_size_hint_weight_set(done_button, 1.0, 1.0);
	evas_object_size_hint_align_set(done_button, -1.0, -1.0);
	elm_box_pack_end(hbox, done_button);
	evas_object_show(done_button);
	evas_object_smart_callback_add(done_button, "clicked", cat_win_del, cat_win);

	populate_cat_list(cat_list);
	// make window full screen
	evas_object_resize(cat_win, 480, 640);
	evas_object_show(cat_win);
}
/*
int check_process_running(void *data, int type, void *event)
{
	char *da = NULL, *ty;
	
	da = (char *)data;
	Ecore_Exe_Event_Data *e_data = (Ecore_Exe_Event_Data *) event;
	ty = strstr((char *)e_data->data, da);
	printf("%s\n", (char *)e_data->data);
	return 0;
}
*/

void ic_noti_clicked(void *data, Evas_Object *obj, void *event_info)
{
	Evas_Object *bg, *inwin, *vbox, *bt, *hbox;
	static Winlist wl;
	char buf[255];
	
	//clear the notification icon
	snprintf(buf, sizeof(buf), "%s/none.png", "/usr/share/launcher");
	elm_icon_file_set(ic_noti, buf, NULL);
	elm_icon_scale_set(ic_noti, 1, 1);
	evas_object_size_hint_min_set(ic_noti, 80, 80);
	
	noti_win = elm_win_add(NULL, "inwin", ELM_WIN_DIALOG_BASIC);
	elm_win_title_set(noti_win, "Notification");
	elm_win_autodel_set(noti_win, 1);

	bg = elm_bg_add(noti_win);
	elm_win_resize_object_add(noti_win, bg);
	evas_object_size_hint_weight_set(bg, 1.0, 1.0);
	evas_object_show(bg);

	inwin = elm_win_inwin_add(noti_win);
	elm_object_style_set(inwin, "minimal_vertical");
	evas_object_show(inwin);

	vbox = elm_box_add(noti_win);
	elm_win_inwin_content_set(inwin, vbox);
	evas_object_show(vbox);

	hbox = elm_box_add(noti_win);
	elm_box_horizontal_set(hbox, 1);
	elm_box_pack_end(vbox, hbox);
	evas_object_show(hbox);
	
/*	lb = elm_label_add(noti_win);
	elm_label_label_set(lb, noti_app);
	elm_box_pack_end(hbox, lb);
	evas_object_show(lb);

	lb = elm_label_add(noti_win);
	elm_label_label_set(lb, noti_mess);
	elm_box_pack_end(hbox, lb);
	evas_object_show(lb);*/

	//add notification button
	bt = elm_button_add(noti_win);
	sprintf(buf, "%s- %s", noti_app[0], noti_mess[0]);
	elm_button_label_set(bt, buf);
	evas_object_size_hint_weight_set(bt, 1.0, 1.0);
	evas_object_size_hint_align_set(bt, 0.5, -1.0);
	elm_box_pack_end(vbox, bt);
	evas_object_show(bt);
	evas_object_smart_callback_add(bt, "clicked", (void *)run_app, &wl);
	
	//add close button
	bt = elm_button_add(noti_win);
	elm_button_label_set(bt, "Done");
	evas_object_size_hint_weight_set(bt, 1.0, 1.0);
	evas_object_size_hint_align_set(bt, 0.5, -1.0);
	elm_box_pack_end(vbox, bt);
	evas_object_show(bt);
	wl.win = noti_win;
	wl.li = NULL;
	evas_object_smart_callback_add(bt, "clicked", cancel_button_clicked, &wl);
	
	evas_object_resize(noti_win, 320, 240);
	evas_object_show(noti_win);
}

void show_apps(void *data, Evas_Object *obj, void *event_info)
{
	Evas_Object *hbox, *bg;
	char buf[255];
	
	show_apps_win = elm_win_add(NULL, "apps_win", ELM_WIN_BASIC);
	elm_win_title_set(show_apps_win, "Applications");
	elm_win_autodel_set(show_apps_win, 1);
	
	//add the desktop hbox
	hbox = elm_box_add(show_apps_win);
	evas_object_size_hint_weight_set(hbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	elm_win_resize_object_add(show_apps_win, hbox);
	evas_object_show(hbox);
	
	//add layout for right screen
	ly_right = elm_layout_add(show_apps_win);
	snprintf(buf, sizeof(buf), "%s/launcher.edj", "/usr/share/launcher");
	elm_layout_file_set(ly_right, buf, "right");
	elm_win_resize_object_add(show_apps_win, ly_right);
	elm_box_pack_end(hbox, ly_right);
	evas_object_show(ly_right);

	//add the background
	bg = elm_bg_add(show_apps_win);
	elm_bg_file_set(bg, wall_path, NULL);
	elm_win_resize_object_add(show_apps_win, bg);
	elm_layout_content_set(ly_right, "bg", bg);
	evas_object_show(bg);
	
	//add the icon table
	tb = elm_table_add(show_apps_win);
	elm_layout_content_set(ly_right, "table", tb);
	evas_object_size_hint_weight_set(tb, 1.0, EVAS_HINT_EXPAND);
	evas_object_size_hint_align_set(tb, -1.0, EVAS_HINT_FILL);	
	evas_object_show(tb);	

	//add category toolbar
	toolbar = elm_toolbar_add(show_apps_win);
	elm_scroller_bounce_set(toolbar, 0, 0);
	elm_layout_content_set(ly_right, "toolbar", toolbar);
	evas_object_show(toolbar);
	add_toolbar_items();

	// make window full screen
	evas_object_resize(show_apps_win, 480, 640);
	evas_object_show(show_apps_win);
	
	elm_toolbar_item_select(tb_item);
}
void test(void *data, Evas_Object *obj, void *event_info)
{
	int t=0;
	
	reload_alarms(&t);
}

void create_gui(Evas_Object *win)
{
	//home page
	Evas_Object *ic_hbox;//, *bg_right;
	Evas_Object *ly, *bt, *quick_tb, *bg, *desk_hbox;//, *fl, *panel;
	char buf[PATH_MAX], launcher_dir[255], pixmaps[255], shr[255], dt[6], yy[9];
	time_t curtime;
	struct tm *loctime;
	
	strcpy(launcher_dir, "/usr/share/launcher");
	strcpy(pixmaps, "/usr/share/pixmaps");
	strcpy(shr, "/usr/share/icons/shr/86x86/apps");
        
	//add the desktop hbox
	desk_hbox = elm_box_add(win);
	evas_object_size_hint_weight_set(desk_hbox, EVAS_HINT_EXPAND, EVAS_HINT_EXPAND);
	elm_win_resize_object_add(win, desk_hbox);
	evas_object_show(desk_hbox);

	//add layout for main screen
	ly = elm_layout_add(win);
	snprintf(buf, sizeof(buf), "%s/launcher.edj", launcher_dir);
	elm_layout_file_set(ly, buf, "centre");
	elm_win_resize_object_add(win, ly);
	elm_box_pack_end(desk_hbox, ly);
	evas_object_show(ly);

	//get the edje object
	main_edje = elm_layout_edje_get(ly);
	edje_object_signal_callback_add(main_edje, "clock_back_clicked", "clock_bg", clock_back_clicked, NULL);
	edje_object_signal_callback_add(main_edje, "settings_clicked", "settings", set_button_clicked, NULL);

	curtime = time (NULL);
	loctime = localtime (&curtime);
	strftime(dt, 20, f_time, loctime);
	edje_object_part_text_set(main_edje, "time", dt);
	strftime(yy, 20, f_date, loctime);
	edje_object_part_text_set(main_edje, "date", yy);
	
	edje_object_part_text_set(main_edje, "no_calls", " ");
	edje_object_part_text_set(main_edje, "no_sms", " ");
	edje_object_part_text_set(main_edje, "location", loc);
	
	//add the background
	bg = elm_bg_add(win);
	elm_bg_file_set(bg, wall_path, NULL);
	elm_layout_content_set(ly, "bg", bg);
	evas_object_show(bg);
	
	//missed hbox
	ic_hbox = elm_box_add(win);
	elm_box_horizontal_set(ic_hbox, 1);
	elm_layout_content_set(ly, "missed", ic_hbox);
	evas_object_show(ic_hbox);

	//add missed calls icon to hbox
	ic_calls = elm_icon_add(win);
	snprintf(buf, sizeof(buf), "%s/none.png", launcher_dir);
	elm_icon_file_set(ic_calls, buf, NULL);
	elm_icon_scale_set(ic_calls, 1, 1);
	evas_object_size_hint_min_set(ic_calls, 80, 80);
	elm_box_pack_end(ic_hbox, ic_calls);
	evas_object_show(ic_calls);
	evas_object_smart_callback_add(ic_calls, "clicked", ic_calls_clicked, NULL);

	//add missed call label
	call_lb = elm_label_add(win);
	elm_label_label_set(call_lb, " ");
	elm_box_pack_end(ic_hbox, call_lb);
	evas_object_show(call_lb);    

	//add sms icon to hbox
	ic_sms = elm_icon_add(win);
	snprintf(buf, sizeof(buf), "%s/none.png", launcher_dir);
	elm_icon_file_set(ic_sms, buf, NULL);
	elm_icon_scale_set(ic_sms, 1, 1);
	evas_object_size_hint_min_set(ic_sms, 80, 80);
	elm_box_pack_end(ic_hbox, ic_sms);
	evas_object_show(ic_sms);
	evas_object_smart_callback_add(ic_sms, "clicked", ic_sms_clicked, NULL);

	//add sms label
	sms_lb = elm_label_add(win);
	elm_label_label_set(sms_lb, " ");
	elm_box_pack_end(ic_hbox, sms_lb);
	evas_object_show(sms_lb);   

/*	//notification hbox
	noti_hbox = elm_box_add(win);
	elm_box_horizontal_set(noti_hbox, 1);
	elm_layout_content_set(ly, "icons", noti_hbox);
	evas_object_show(noti_hbox);

	//add notifications icon to hbox
	ic_noti = elm_icon_add(win);
	snprintf(buf, sizeof(buf), "%s/none.png", launcher_dir);
	elm_icon_file_set(ic_noti, buf, NULL);
	elm_icon_scale_set(ic_noti, 1, 1);
	evas_object_size_hint_min_set(ic_noti, 80, 80);
	elm_box_pack_end(noti_hbox, ic_noti);
	evas_object_show(ic_noti);
	evas_object_smart_callback_add(ic_noti, "clicked", ic_noti_clicked, NULL);*/

	//add a table
	quick_tb = elm_table_add(win);
	elm_layout_content_set(ly, "quick", quick_tb);
	evas_object_show(quick_tb);
	add_toolbar_home_items(quick_tb);

	//add flip button
	bt = elm_button_add(win);
	elm_button_label_set(bt, "Apps");
	elm_layout_content_set(ly, "button", bt);
	evas_object_smart_callback_add(bt, "clicked", show_apps, NULL);
	//evas_object_smart_callback_add(bt, "clicked", test, NULL);
	evas_object_show(bt);
	    
	// make window full screen
	evas_object_resize(win, 480, 640);
	timer = ecore_timer_add(5.0, clock_func, NULL);
}	
